#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <string.h>
#include <queue>
#include <math.h>
using namespace std;
struct Node {
	string name;
	int id;
	double payed;
	double op_num;
	string op_string;
	Node() {};
	Node(string _name, double _payed) :name(_name), payed(_payed){};
}p[10];
bool cmp(Node a, Node b)
{
	return a.op_num < b.op_num;
}
map< string , int > mp;
map< string , string > mp1;
int main()
{

	//2021/5/7-2021/5/27
	// string s = "A payed 80;B payed 20;C payed 0;D payed 110;E payed 0;";
	//2021/6/3-2021/7/15
	
	// string s = "A payed 50;B payed 10;C payed20;D payed 250;E payed 200;";// 未算朱志康多出的水费和谢卓君多出的电费
	// string s = "A payed 50;B payed 10;C payed 20;D payed 230;E payed 170;";	// 算朱志康多出的水费(20元)和谢卓君多出的电费(30元)
	//2021/9/3 对冲后即孙煜海交50元

	//2021/9/6-2021/10/1,结账日期：2021/10/1
	// string s = "A payed 0;B payed 10;C payed 10;D payed 30;E payed 300;";

	//2021/10/6-2021/10/28,结账日期2021/10/31
	// string s = "A payed 10;B payed 10;C payed 0;D payed 35.8;E payed 100;";//由于D的35.8出错，将35.8改为36
	string s = "A payed 10;B payed 10;C payed 0;D payed 36;E payed 100;";


	char ss = 'A';
	string temp = "";
	for (int i = 1; i <= 5; i++)
	{
		temp += ss;
		ss++;
		mp[temp] = i;
		p[i].id = i;
		p[i].name = temp;
		temp.clear();
	}
	for (int i = 1; i <= 5; i++)
	{
		if (p[i].id == 1)
			p[i].name = "孙睿哲";
		else if (p[i].id == 2)
			p[i].name = "吴家栋";
		else if (p[i].id == 3)
			p[i].name = "孙煜海";
		else if (p[i].id == 4)
			p[i].name = "朱志康";
		else if (p[i].id == 5)
			p[i].name = "谢卓君";
	}
	int len = s.length();
	int j;
	for (int i = 0; i < len; i=j+1)
	{
		if (i==0||s[i-1]==';')
		{
			string tmp_name = "";
			j = i;
			for (; s[j] != ' '&&j<len; j++)
				tmp_name += s[j];
			string num_string = "";
			j += 7;
			for (;s[j] != ';'&&j < len; j++)
				num_string += s[j];
			int len_num = num_string.length();
			int id = -1;
			for (int k = 0; k < len_num; k++)
			{
				if (num_string[k] == '.')
				{
					id = k;
					break;
				}
			}
			if (id == -1)
				id = len_num - 1;
			else
				id--;
			double Int_part = 0.0;
			double tmp_bit = 1.0;
			for (int k = id; k >= 0; k--)
			{
				Int_part += tmp_bit *(num_string[k] - '0');
				tmp_bit *= 10.0;
			}
			double Flt_part = 0;
			tmp_bit = 0.1;
			for (int k = id + 2; k < len_num; k++)
			{
				Flt_part += tmp_bit * (num_string[k] - '0');
				tmp_bit /= 10.0;
			}
			double num_tot = Int_part + Flt_part;
			p[mp[tmp_name]].payed=num_tot;
		}
	}
	double ave_payed = 0.0;
	for (int i = 1; i <= 5; i++)
		ave_payed += p[i].payed;
	ave_payed /= 5.0;
	for (int i = 1; i <= 5; i++)
		p[i].op_num =  p[i].payed - ave_payed;
	//printf("%.2lf", ave_payed);
	sort(p + 1, p + 6, cmp);
	int num = 0;
	for (int i = 1; i <= 5; i++)
	{
		if (p[i].op_num < 0)
			num++;
	}
	int id1 = num, id2 = num + 1;
	string ans = "";
	while (id1 >= 1)
	{
		if (fabs(p[id1].op_num) > p[id2].op_num)
		{
			char strN[50];
			sprintf(strN, "%.2lf", p[id2].op_num);
			if (fabs(p[id2].op_num - 0.0) < 1e-6)
			{
				id2++;
				continue;
			}
			ans+=p[id1].name+"给"+p[id2].name+""+strN+"元;\n";
			p[id1].op_num += p[id2].op_num, p[id2].op_num = 0, id2++;
		}
		else
		{
			char strN[50];
			sprintf(strN, "%.2lf",fabs(p[id1].op_num));
			if (fabs(fabs(p[id1].op_num) - 0.0) < 1e-6)
			{
				id1--;
				continue;
			}
			ans+=p[id1].name+"给"+p[id2].name+""+strN+"元;\n";
			p[id2].op_num += p[id1].op_num, p[id1].op_num = 0, id1--;
		}
	}
	cout << ans;
}

